package com.zmn.plat.services.impl.orderconfig.returnvisitcontent;

import java.util.List;
import java.util.Objects;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zmn.common.dto.StatusDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.orderconfig.returnvisitcontent.ReturnVisitQuestion;
import com.zmn.plat.model.entity.orderconfig.returnvisitcontent.ReturnVisitQuestionQuery;
import com.zmn.plat.persistence.interfaces.orderconfig.returnvisitcontent.ReturnVisitQuestionDao;
import com.zmn.plat.services.interfaces.orderconfig.returnvisitcontent.ReturnVisitQuestionService;

import lombok.extern.slf4j.Slf4j;

/**
 * 描述: 回访内容表基础接口实现类
 *
 * @author tanghongjun
 * @since 2020-04-14 11:27:25
 **/
@Slf4j
@Service
public class ReturnVisitQuestionServiceImpl implements ReturnVisitQuestionService {

    private static final String TAG = "回访内容表基础服务接口";

    @Resource
    private ReturnVisitQuestionDao returnVisitQuestionDao;

    /**
     * 描述: 根据id查询数据
     *
     * @param questionId
     *            id
     * @author tanghongjun
     * @since 2020-04-14 11:27:25
     **/
    @Override
    public ReturnVisitQuestion findById(Integer questionId) {

        if (Objects.isNull(questionId)) {
            log.error("[{}],根据id查询数据questionId为null", TAG);
            return null;
        }
        return returnVisitQuestionDao.findById(questionId);
    }

    @Override
    public Integer findMaxSort() {
        return returnVisitQuestionDao.findMaxSort();
    }

    /**
     * 描述: 按条件查询数据 支持分页
     *
     * @param query
     *            查询对象
     * @author tanghongjun
     * @since 2020-04-14 11:27:25
     **/
    @Override
    public List<ReturnVisitQuestion> listPageByQuery(ReturnVisitQuestionQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        int count = returnVisitQuestionDao.countByQuery(query);
        query.setTotalCount(count);
        return returnVisitQuestionDao.listPageByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query
     *            查询对象
     * @author tanghongjun
     * @since 2020-04-14 11:27:25
     **/
    @Override
    public List<ReturnVisitQuestion> listByQuery(ReturnVisitQuestionQuery query) {
        return returnVisitQuestionDao.listByQuery(query);
    }

    /**
     * 描述: 根据id修改数据 id为必传
     *
     * @param returnVisitQuestion
     *            待修改数据
     * @return java.lang.Integer
     * @author tanghongjun
     * @since 2019/11/12
     **/
    @Override
    public Integer updateReturnVisitQuestionByKey(ReturnVisitQuestion returnVisitQuestion) {
        return returnVisitQuestionDao.updateReturnVisitQuestionByKey(returnVisitQuestion);
    }

    @Override
    public int updateStatusBatch(List<Integer> arrayIds, int status, String updater) {
        StatusDTO dto = new StatusDTO();
        dto.setIds(arrayIds);
        dto.setStatus(status);
        dto.setUpdater(updater);
        dto.setUpdateTime(DateUtil.getNow());
        return returnVisitQuestionDao.updateStatusBatch(dto);
    }

    @Override
    public Integer updateSortKey(int id, int sort, String updater) {
        ReturnVisitQuestion returnVisitQuestion = new ReturnVisitQuestion();
        returnVisitQuestion.setQuestionId(id);
        returnVisitQuestion.setSort(sort);
        returnVisitQuestion.setUpdater(updater);
        returnVisitQuestion.setUpdateTime(DateUtil.getNow());
        return returnVisitQuestionDao.updateSortKey(returnVisitQuestion);
    }

    @Override
    public Integer updateFirstLetterByKey(int id, String firstLetter, String updater) {
        ReturnVisitQuestion returnVisitQuestion = new ReturnVisitQuestion();
        returnVisitQuestion.setQuestionId(id);
        returnVisitQuestion.setFirstLetter(firstLetter);
        returnVisitQuestion.setUpdater(updater);
        returnVisitQuestion.setUpdateTime(DateUtil.getNow());
        return returnVisitQuestionDao.updateFirstLetterByKey(returnVisitQuestion);
    }

    /**
     * 描述: 新增数据
     *
     * @param returnVisitQuestion
     *            待新增数据
     * @return java.lang.Integer 主键key
     * @author tanghongjun
     * @since 2019/11/12
     **/
    @Override
    public Integer insert(ReturnVisitQuestion returnVisitQuestion) {
        return returnVisitQuestionDao.insert(returnVisitQuestion);
    }

}